<?php
/**
 * @author Mingming Tang iamalazyrat@gmail.com
 */

class Register_Controller extends Base_Controller {

  public $restful = true;

  public function get_index() {
    return Redirect::to(url('register/new'));
  }

  public function get_new() {
    return View::make('register.new.main');
  }

  public function post_new() {
    $email = Input::get('email', '');
    $password = Input::get('password', '');
    if (!$email OR !$password) return Response::json(array('code'=>400, 'msg' => '输入有误'));
    if (!filter_var($email, FILTER_VALIDATE_EMAIL)) return Response::json(array('code'=>400, 'msg'=>'登录邮箱格式不正确'));
    if (trim($password) == '') return Response::json(array('code'=>400, 'msg'=>'登录密码为空或全为空格'));
    $user = User::where('email', '=', $email)->first();
    if ($user) return Response::json(array('code'=>400, 'msg'=>'email已经存在'));
    $user = User::create(array('email'=>$email, 'password'=>Hash::make($password)));
    if ($user) return Response::json(array('code'=>200, 'msg'=>'注册成功')); 
    return Response::json(array('code'=>400, 'msg'=>'注册失败'));
  }

  public function get_msg() {
    $email = Input::get('email', '');
    $user = User::where('email', '=', $email)->first();
    return View::make('register.msg.main')->with('user', $user);
  }

  public function post_in() {
  }

  public function get_out() {
  }
  
}
